package com.gw.vip.server.controller;

import com.gw.vip.common.exception.ExceptionEnums;
import com.gw.vip.common.exception.ServiceException;
import com.gw.vip.common.log.PrintlnLog;
import com.gw.vip.common.vo.Result;
import com.gw.vip.server.dto.PingDto;
import com.gw.vip.server.vo.PingVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author GW
 * @description 健康检查
 * @since 2022-07-18
 */
@RestController
@RequestMapping("health")
@Slf4j
public class HealthController {
    @PrintlnLog(description = "pingPong检查")
    @PostMapping("ping")
    public Result ping(@RequestBody @Valid PingDto dto){
        if (!dto.getSay().equals("ping")){
            log.error("请说ping！");
            throw new ServiceException(ExceptionEnums.ERROR_PARAMS, "请说ping!");
        }
        PingVo vo = new PingVo();
        vo.setSay("pong");
        return Result.success(vo);
    }
}
